/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Index;

import BLL.Parameter_BLL;
import DTO.Parameter_DTO;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Nguyen Phi Hung
 */
public class JIF_Parameter extends javax.swing.JInternalFrame {
    //khai bao bien Parameter
    
    
    public void LoadParameter() throws Exception{
        Parameter_DTO param = new Parameter_DTO();
        Parameter_BLL param_bll = new Parameter_BLL();
    
        HashSet<Parameter_DTO> params = param_bll.getParameters();
        param = params.toArray(new Parameter_DTO[params.size()])[0];
        this.txt_MinOfDeposit.setText(param.getMinofDeposit()+"");
        this.txt_MinOfWithDraw.setText(param.getMinOfWithdraw()+"");
        this.txt_FirstMinOfDeposit.setText(param.getFirstMinOfDeposit() + "");
        this.txt_InterestFreePeriod.setText(param.getInterestFreePeriod() +"");
        this.txt_MinOfDepositPeriod.setText(param.getMinOfDepositPeriod()+"");
    }
    /**
     * Creates new form JInterFrame_Parameter
     */
    public JIF_Parameter() throws Exception {
        initComponents();
        LoadParameter();
        setEnable_textfield(false);
        setEditable_button(false);
        this.txt_FirstMinOfDeposit.setHorizontalAlignment(txt_FirstMinOfDeposit.RIGHT);
        this.txt_InterestFreePeriod.setHorizontalAlignment(txt_InterestFreePeriod.RIGHT);
        this.txt_MinOfDeposit.setHorizontalAlignment(txt_MinOfDeposit.RIGHT);
        this.txt_MinOfDepositPeriod.setHorizontalAlignment(txt_MinOfDepositPeriod.RIGHT);
        this.txt_MinOfWithDraw.setHorizontalAlignment(txt_MinOfWithDraw.RIGHT);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        btn_chinhsua = new javax.swing.JButton();
        txt_MinOfDeposit = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txt_MinOfWithDraw = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txt_FirstMinOfDeposit = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txt_MinOfDepositPeriod = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txt_InterestFreePeriod = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        btn_default = new javax.swing.JButton();

        jLabel1.setText("Số tiền gửi tối thiểu:");

        btn_chinhsua.setText("Chỉnh sửa");
        btn_chinhsua.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_chinhsuaMouseClicked(evt);
            }
        });

        jLabel2.setText("Số tiền rút tối thiểu:");

        jLabel3.setText("Số tiền gửi tối thiểu ban đầu :");

        jLabel5.setText("Thời gian tối thiểu để được rút:");

        jLabel6.setText("Số ngày không tính lãi kể từ ngày gửi:");

        jLabel4.setText(" (VND)");

        jLabel9.setText("(Ngày)");

        jLabel7.setText(" (VND)");

        jLabel8.setText(" (VND)");

        jLabel10.setText("(Ngày)");

        btn_default.setText("Quay về mặc định");
        btn_default.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_defaultActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txt_MinOfWithDraw)
                            .addComponent(txt_MinOfDeposit)
                            .addComponent(txt_FirstMinOfDeposit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txt_InterestFreePeriod)
                            .addComponent(txt_MinOfDepositPeriod, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel4)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10)))
                        .addGap(8, 8, 8))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btn_chinhsua, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btn_default, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txt_MinOfDeposit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_MinOfWithDraw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txt_FirstMinOfDeposit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txt_MinOfDepositPeriod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txt_InterestFreePeriod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_default)
                    .addComponent(btn_chinhsua))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    int clickcount = 0;
    
    private void btn_defaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_defaultActionPerformed
        Parameter_DTO param = new Parameter_DTO();
        Parameter_BLL param_bll = new Parameter_BLL();
        
        param.setFirstMinOfDeposit((float) 100000);
        param.setInterestFreePeriod(15);
        param.setMinOfDepositPeriod(5);
        param.setMinOfWithdraw(100000);
        param.setMinofDeposit(200000);
        
        try {
            param_bll.Update(param);
            this.LoadParameter();
        } catch (Exception ex) {
            Logger.getLogger(JIF_Parameter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_defaultActionPerformed
    
    public void setEditable_button(boolean status){
        this.txt_FirstMinOfDeposit.setEditable(status);
        this.txt_InterestFreePeriod.setEditable(status);
        this.txt_MinOfDeposit.setEditable(status);
        this.txt_MinOfDepositPeriod.setEditable(status);
        this.txt_MinOfWithDraw.setEditable(status);
    }
    
    public void setEnable_textfield(boolean status){
        this.txt_FirstMinOfDeposit.setEnabled(status);
        this.txt_InterestFreePeriod.setEnabled(status);
        this.txt_MinOfDeposit.setEnabled(status);
        this.txt_MinOfDepositPeriod.setEnabled(status);
        this.txt_MinOfWithDraw.setEnabled(status);
    }
    private void btn_chinhsuaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_chinhsuaMouseClicked
        // TODO add your handling code here:
        clickcount++;
        //JOptionPane.showMessageDialog(null, clickcount);
        if(clickcount %2 == 0){
            setEditable_button(false);
            setEnable_textfield(false);
        } else{
            setEditable_button(true);      
            setEnable_textfield(true);
        }
                  
    }//GEN-LAST:event_btn_chinhsuaMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_chinhsua;
    private javax.swing.JButton btn_default;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField txt_FirstMinOfDeposit;
    private javax.swing.JTextField txt_InterestFreePeriod;
    private javax.swing.JTextField txt_MinOfDeposit;
    private javax.swing.JTextField txt_MinOfDepositPeriod;
    private javax.swing.JTextField txt_MinOfWithDraw;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the clickcount
     */
    public int getClickcount() {
        return clickcount;
    }

    /**
     * @param clickcount the clickcount to set
     */
    public void setClickcount(int clickcount) {
        this.clickcount = clickcount;
    }
}
